<?php	
/*\
 *	oh.url.interface.php
 *	--------------------
 *	name: url
 *	desc: 
 *	hash:
 *	date: 
\*/

#module main function
function oh_function_url($m) {
	global $oh_object_url;
	if (count($m->token)>0) {
		if ($m->token[0]=='tools') {
			return oh_this();
		}
		if ($m->token[0]=='framework') {
			if (count($m->token)>1) {
				$tokens = implode("/",array_slice($m->token[0],1));
				//return $oh_object_url->oh_url_framework()."/".$tokens;				
			} else {
				//return $oh_object_url->oh_url_framework();				
			}				
		}
		if ($m->token[0]=='script') {
			return 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
		}
	}
	return 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];	
} 

#module main class
class oh_class_url {		
	function oh_class_url() {
	}
	// restituisce url della cartella principale del framweork
	function oh_url_framework() {
		global $oh;

		$sk1 = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
		$sk2 = $_SERVER["SCRIPT_FILENAME"];			
		$sk3 = dirname($_SERVER["SCRIPT_FILENAME"]);
		$sk4 = dirname($oh['path']);			
		
		$a_sk1 = explode("/",$sk1);
		$a_sk2 = explode("/",$sk2);
		$a_sk3 = explode("/",$sk3);
		$a_sk4 = explode("/",$sk4);
		
		if ($sk3 == $sk4) {
			return dirname($sk1)."/oh.framework";
		}
		if (count($a_sk3)>count($a_sk4)) {
			$t3 = $sk3;
			$t4 = $sk4;
			$c 	= 0;
			while(($t3!=$t4)&&($c<10)) {
				$t3 = dirname($t3);
				$c++;
			}
			return aa_prog(dirname($sk1),$c)."/oh.framework";
		} else {
			$t3 = $sk3;
			$t4 = $sk4;
			$t 	= oh("string")->charmaxquot($t3,$t4);
			$tj1 = substr($t4,$t[1]);
			$k =  oh("string")->charmaxquot($tj1,dirname($sk1));
			return substr(dirname($sk1),0,$k[1]).$tj1."/oh.framework";			
		}
		/*
		echo '-'.$c;			
		echo '<br>';
		//echo aa_diff($sk1,$sk2,-1,0);
		echo aa_delta($sk1,$sk2,true)."<br/>";
		echo aa_diff($sk1,$sk2,0,-18,true);

		echo '<table border="1">';			
		for ($i=-19;$i<20;$i++) {
			echo '<tr>';
			echo '<td>'.$i.'</td>';
			echo '<td>'.@$sk1[$i+$d1].'</td>';
			echo '<td>'.@$sk2[$i+$d2].'</td>';
			echo '<td>'.@$sk3[$i+$d3].'</td>';
			echo '</tr>';
		}
		echo '</table>';			
		*/
		return $this->oh_cut($sk1).$this->oh_pls()."/oh.framework";
	}
	// ritaglia da
	function oh_cut($u) {
		return $u;	
	}
	function oh_pls() {
		return "";
	}
	// tools
	function sanitize($url) {
		if (substr($url,0,7) == "http://") {
			return $url;
		} else {
			return "http://".$url;
		}			
	}
}
	
#module main object
global $oh_object_url;
$oh_object_url = new oh_class_url();
